package cn.appsys.controller.dev;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.appsys.pojo.DevUser;
import cn.appsys.service.DevUserService;

@Controller
public class DevUserController {

	@Autowired
	DevUserService devUserService;

	@RequestMapping("dev/login")
	public String login() {
		return "devlogin";
	}

	@RequestMapping("/dev/dologin")
	public String dologin(String devCode, String devPassword, Model model, HttpSession session) {
		DevUser user = devUserService.login(devCode, devPassword);
		if (user != null) {
			session.setAttribute("devUserSession", user);
			return "redirect:main";
		}
		model.addAttribute("error", "用户名密码错误");
		return "devlogin";
	}

	@RequestMapping("dev/main")
	public String main(){
		return "developer/main";
	}
	
	@RequestMapping("dev/logout")
	public String logout(HttpSession session){
		session.invalidate();
		return "redirect:login";
	}
}
